<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>

<script>
    /*
        1.防止变量污染
        2.变量私有化
        3.延长变量生命周期

        案列 防抖 和节流 工具库的封装
    */

    // 计数案例


    const obj = {
        name:'lt'
    }


    function count(){
        console.log(this.name);
        let num = 0
        const changeNum = (val) => {
            num += val
        }
        return {
            increase(){
                changeNum(1)
            },
            decrease(){
                changeNum(-1)
            },
            getNum(){
                return num
            }
        }
    }

    const c = count()
    console.log(c.getNum());
    c.increase()
    c.increase()
    c.decrease()
    console.log(c.getNum());
    //  0 1 
    count.call(obj)

</script>

</html>